package com.qf.commons.web.config;

import com.qf.commons.web.aop.AuthInfoAspect;
import com.qf.commons.web.aspect.LogAdviceAspect;
import com.qf.commons.web.exception.GlobalExceptionHandler;
import com.qf.commons.web.feign.RequestParamHandler;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * description: 核心配置类
 * author: Ken
 * 公众号：Java架构栈
 */
@Configuration
@ComponentScan("com.qf.commons.web.exception.handler")
@EnableDiscoveryClient
@EnableFeignClients(basePackages = "com.qf.**.feign",defaultConfiguration = RequestParamHandler.class)
public class WebAutoConfiguration implements WebMvcConfigurer {

    /**
     * 注册统一异常处理器
     * @return
     */
    @Bean
    public GlobalExceptionHandler getGloablExceptionHandler(){
        return new GlobalExceptionHandler();
    }

    /**
     * 日志增强的切面 - 拦截所有的Controller方法
     * @return
     */
    @Bean
    public LogAdviceAspect getLogAdviceAspect(){
        return new LogAdviceAspect();
    }


    /**
     * 解析用户身份的切面 - 拦截所有的controller方法
     * @return
     */
    @Bean
    public AuthInfoAspect getAuthInfoAspect(){return new AuthInfoAspect();}

}
